package com.zjsd.sqeybusiness.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zjsd.sqeybusiness.domain.Cost;
import com.zjsd.sqeybusiness.service.ICostService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author Zheng
 * @date 2021-07-20
 */
@RestController
@RequestMapping("/sqeybusiness/cost")
public class CostController extends BaseController
{
    @Autowired
    private ICostService costService;

    /**
     * 查询【请填写功能名称】列表  @PreAuthorize("@ss.hasPermi('sqeybusiness:cost:list')")
     */

    @GetMapping("/list")
    public TableDataInfo list(Cost cost)
    {
        // startPage();
        List<Cost> list = costService.selectCostList(cost);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('sqeybusiness:cost:export')")
    //@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Cost cost)
    {
        List<Cost> list = costService.selectCostList(cost);
        ExcelUtil<Cost> util = new ExcelUtil<Cost>(Cost.class);
        return util.exportExcel(list, "cost");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('sqeybusiness:cost:query')")
    @GetMapping(value = "/{costid}")
    public AjaxResult getInfo(@PathVariable("costid") Long costid)
    {
        return AjaxResult.success(costService.selectCostById(costid));
    }

    /**
     * 新增【请填写功能名称】@PreAuthorize("@ss.hasPermi('sqeybusiness:cost:add')")
     */

    //@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cost cost)
    {
        return toAjax(costService.insertCost(cost));
    }

    /**
     * 修改【请填写功能名称】  @PreAuthorize("@ss.hasPermi('sqeybusiness:cost:edit')")
     */

    //@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cost cost)
    {
        return toAjax(costService.updateCost(cost));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('sqeybusiness:cost:remove')")
    //@Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{costids}")
    public AjaxResult remove(@PathVariable Long[] costids)
    {
        return toAjax(costService.deleteCostByIds(costids));
    }
}
